﻿using ProTrack.IRepository;
using ProTrack.IServices;
using ProTrack.Utility;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace ProTrack.Services
{
    public class AccountServices : IAccountServices
    {
        private readonly IBaseRepository db;

        public AccountServices(IBaseRepository db)
        {
            this.db = db;
        }


        public async Task<bool> Signin(string UserName, string PassWord)
        {

            var pwd = AESEncryptHelper.Encode(PassWord);

            string sql = "select count(*) from SystemUsers where UserName=@UserName and  Password=@Password";
            var result = await db.GetRecoreCountAsync(sql,new { UserName , PassWord= pwd });

            return result > 0;
        }


        public async Task<int> GetUserIdByUserName(string UserName)
        {
            string sql = "select Id from SystemUsers where UserName=@UserName ";
            var result = await db.GetRecoreCountAsync(sql, new { UserName});
            return result;
        }
    }
}
